<?php

namespace app\common\validate;


class Banner extends BaseValidate {
    protected $rule = [
        'status'       => 'in:0,1,2,3',
        'total'        => 'eq:1',
        'position_id'  => 'in:0,1,2,3',
        'age'          => 'require',
        'position_ids' =>'require|checkIDs'
    ];
    protected $message = [
        'status' => 'status必须在0,1,2,3之间'
    ];
    protected $scene = [
        'xcx'   => [''],
        'admin' => ['position_id', 'total', 'status']
    ];

    protected function checkIDs($value) {
        $values = explode(',', $value);
        if (empty($values)) {
            return false;
        }
        foreach ($values as $id) {
            if (!$this->isPositiveInteger($id)) {
                return false;
            }
        }
        return true;
    }
}